<?php

namespace App\Admin\Controllers;

use Encore\Admin\Grid;
use App\Models\UpgradeLog;
use Encore\Admin\Controllers\AdminController;

class UpgradeLogsController extends AdminController
{
    protected $title = '升级记录明细';

    protected function grid()
    {
        $grid = new Grid(new UpgradeLog());
        $grid->model()->orderByDesc('id');

	    if ($userId = request('user_id')) {
		    $grid->model()->where('user_id', $userId)->orderByDesc('id');
	    }

        $grid->column('id', 'ID');
        $grid->column('user_id', '会员')->display(function () {
        	return $this->user ? $this->user->nameText(true) : '';
        });
        $grid->column('reason', '事由');
        $grid->column('created_at', '记录时间')->display(function () {
        	return (string)$this->created_at;
        });

	    $this->gridFilter($grid);

	    $grid->disableRowSelector();
	    $grid->disableCreateButton();
	    $grid->disableExport();
	    $grid->disableActions();

        return $grid;
    }

    protected function gridFilter(Grid $grid)
    {
    	$grid->filter(function (Grid\Filter $filter) {
    		$filter->expand();
		    $filter->column(1/2, function (Grid\Filter $filter) {
			    $filter->disableIdFilter();
			    $filter->equal('user_id', '会员 ID 查询');
		    });
	    });
    }
}
